package com.cat.dynamicPlanning02;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/reducing-dishes/description/?envType=problem-list-v2&envId=Yvc80cti
 * @create 2025/10/1 22:05
 * @since JDK17
 */

public class Solution16 {
    public int maxSatisfaction(int[] satisfaction) {
        int n = satisfaction.length;
        long ans = 0, sum = 0;
        Arrays.sort(satisfaction);
        for (int i = 0; i < n; i++) {
            sum = 0;
            for (int j = i, cnt = 1; j < n; j++, cnt++) {
                sum += satisfaction[j] * cnt;
            }
            ans = Math.max(ans, sum);
        }

        return ((int) ans);
    }
}
